package utils;

public class ListIterator<T> {
	private Node<T> current;
	private Node<T> start;
	private boolean started = false;
	
	public ListIterator(Node<T> current)
	{
		this.current = current;
		start = current;
	}
	
	public boolean hasNext()
	{
		return started ? (start != current) : true; 
	}
	
	public boolean hasPrev()
	{
		return started ? (start != current) : true;
	}
	
	public Node<T> next()
	{	
		Node<T> target = current;
		
		if(hasNext())
			current = current.next;
		
		if(!started)
			started = true;
		
		return target;
	}
	
	public Node<T> prev()
	{
		Node<T> target = current;
				
		if(hasPrev())
			current = current.prev;
		
		if(!started)		
			started = true;
		
		return target;
	}
}
